<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a>对账</a>
        <a>
            <cite>商户对账</cite>
        </a>
    </div>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">对账文件</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-row">
                        <div class="layui-form" style="float:right; margin-bottom: 10px;">
                            <div class="layui-form-item" style="margin:0;">
                                <div class="layui-input-inline">
                                    <input type="text" name="mchId" id="mchId" placeholder="商户ID" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-input-inline">
                                    <input type="text" name="billDate" id="billDate" placeholder="对账日期" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-input-inline">
                                    <select name="type" id="status" lay-search="">
                                        <option value="-99">状态</option>
                                        <option value="0">未生成</option>
                                        <option value="1">已生成</option>
                                    </select>
                                </div>
                                <button id="search" class="layui-btn" data-type="reload">搜索</button>
                            </div>
                        </div>
                    </div>
                    <table id="JeePay_Mgr_PayOrder_dataAll" lay-filter="JeePay_Mgr_PayOrder_dataAll"></table>
                </div>

            </div>
        </div>
    </div>
</div>

<script type="text/html" id="jeepayBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    <a target="_blank" class="layui-btn layui-btn-primary layui-btn-xs" lay-event="download">下载</a>
</script>

<script>
    layui.use(['admin', 'table', 'util'], function () {
        var $ = layui.$,
            admin = layui.admin,
            table = layui.table,
            element = layui.element,
            form = layui.form;

        element.render('breadcrumb', 'breadcrumb');

        //用户列表
        table.render({
            elem: '#JeePay_Mgr_PayOrder_dataAll',
            url: layui.setter.baseUrl + '/bill/mch/list' //列表接口
                ,
            where: {
                access_token: layui.data(layui.setter.tableName).access_token
            },
            id: 'tableReload',
            page: true,
            cols: [
                [{
                    type: 'checkbox',
                    fixed: 'left'
                }, {
                    field: 'billDate',
                    title: '对账日期',
                    templet: '<div>{{ layui.util.toDateString(d.createTime, "yyyy-MM-dd") }}</div>'
                }, {
                    field: 'mchId',
                    title: '商户ID'
                },  {
                    field: 'mchType',
                    title: '商户类型',
                    templet: '<div>{{ d.mchType == 1?"平台账户":"私有账户" }}</div>'
                }, {
                    field: 'status',
                    title: '状态',
                    templet: '<div>{{ d.status == 0?"未生成":"已生成" }}</div>'
                },  {
                    field: 'createTime',
                    title: '创建时间',
                    templet: '<div>{{ layui.util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss") }}</div>'
                }, {
                    field: 'edit',
                    title: '操作',
                    toolbar: '#jeepayBar'
                }]
            ],
            skin: 'line'
        });

        //监听工具条
        table.on('tool(JeePay_Mgr_PayOrder_dataAll)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                location.hash = "/reconciliation/mch_bill/view/id=" + data.id;
            }else if(obj.event === 'download') {
                // location.href = data.billPath;
                window.open(data.billPath) ;
            }
        });

        // 搜索
        var $ = layui.$,
            active = {
                reload: function () {
                    var mchId = $('#mchId').val();
                    var status = $("#status").val();
                    var billDate = $("#billDate").val();
                    //执行重载
                    table.reload('tableReload', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        },
                        where: {
                            mchId: mchId,
                            status: status,
                            billDate: billDate
                        }
                    });
                }
            };
        $('#search').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        // 渲染表单
        form.render();
    });
</script>